<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>入门案例</title>
</head>
<body>
<button onclick="fn1()">AJAX</button>
</body>
<script>
    function fn1(){
        //创建XMLHttpRequest对象
        var xhr = new XMLHttpRequest();
        //监听XMLHttpRequest对象状态改变
        xhr.onreadystatechange = function () {
            if (xhr.status == 200 && xhr.readyState == 4){
               //异步请求成功
               //json字符串
               var responseText = xhr.responseText;
               console.log(responseText);
               //json字符串转js对象
                var jsObj = JSON.parse(responseText);
                console.log(jsObj.msg);
            }

        }
        //打开连接
        xhr.open("get","/day12/demo01?uesrname =root&password=root",true);
        //发送参数
        xhr.send();
    }
</script>
</html>